clear
cd "data directory here" 
use socialsurveydata.dta
 
gen working = 0 
gen searching = 0 
gen housework = 0 
gen study = 0 
gen other = 0 
gen childcare = 0 

gen type1 = 0
replace type1 = 1 if year == 1993
replace type1 = 1 if year == 1994
replace type1 = 1 if year == 1995
replace type1 = 1 if year == 1996

gen type2 = 0 
replace type2 = 1 if year == 1997

gen type3 = 0 
replace type3 = 1 if year == 1998
replace type3 = 1 if year == 1999
replace type3 = 1 if year == 2000

gen type4 = 0 
replace type4 = 1 if year == 2001
replace type4 = 1 if year == 2002

gen type5 = 0 
replace type5 = 1 if year == 2003
replace type5 = 1 if year == 2004
replace type5 = 1 if year == 2005


replace working = 1   if empstat == 1  & type1 == 1
replace searching = 1 if empstat == 2  & type1 == 1
replace housework = 1 if empstat == 3  & type1 == 1
replace study = 1     if empstat == 4  & type1 == 1
replace other = 1     if empstat == 5  & type1 == 1

replace working = 1   if empstat == 1  & type2 == 1
replace searching = 1 if empstat == 2  & type2 == 1
replace housework = 1 if empstat == 3  & type2 == 1
replace childcare = 1 if empstat == 4  & type2 == 1
replace study = 1     if empstat == 5  & type2 == 1
replace other = 1     if empstat == 6  & type2 == 1

replace working = 1   if empstat == 1  & type3 == 1
replace searching = 1 if empstat == 2  & type3 == 1
replace childcare = 1 if empstat == 3  & type3 == 1
replace housework = 1 if empstat == 4  & type3 == 1
replace study = 1     if empstat == 5  & type3 == 1
replace other = 1     if empstat == 6  & type3 == 1

replace working = 1   if empstat == 1  & type4 == 1
replace searching = 1 if empstat == 2  & type4 == 1
replace searching = 1 if empstat == 3  & type4 == 1
replace childcare = 1 if empstat == 4  & type4 == 1
replace housework = 1 if empstat == 5  & type4 == 1
replace study = 1     if empstat == 6  & type4 == 1
replace other = 1     if empstat == 7  & type4 == 1
replace other = 1     if empstat == 8  & type4 == 1
replace other = 1     if empstat == 9  & type4 == 1

replace working = 1   if empstat == 1 & type5 == 1
replace searching = 1 if empstat == 2 & type5 == 1
replace other = 1     if empstat == 3 & type5 == 1
 
gen employer = 0 
gen selfemployed = 0 
gen familyworker = 0 
gen worker = 0 
gen worker_temp = 0
gen worker_daily = 0 

gen wtype1 = 0 
replace wtype1 = 1 if year<=1998
gen wtype2 = 0
replace wtype2 = 1 if year >=1999

replace employer = 1 if wtype1 == 1 & workerstatus == 1
replace selfemployed = 1 if wtype1 == 1 & workerstatus == 2
replace familyworker = 1 if wtype1 == 1 & workerstatus == 3
replace worker = 1 if wtype1 == 1 & workerstatus == 4
replace worker_temp = 1 if wtype1 == 1 & workerstatus == 5
replace worker_daily = 1 if wtype1 == 1 & workerstatus == 6

replace worker = 1 if wtype2 == 1 & workerstatus == 1
replace worker_temp = 1 if wtype2 == 1 & workerstatus == 2
replace worker_daily = 1 if wtype2 == 1 & workerstatus == 3
replace employer = 1 if wtype2 == 1 & workerstatus == 4
replace selfemployed = 1 if wtype2 == 1 & workerstatus == 5
replace familyworker = 1 if wtype2 == 1 & workerstatus == 6
 
sort hhid relationship
bys year hhid: gen Head = 1   if relationship == 1
bys year hhid: gen Spouse = 1 if relationship == 2

bys year hhid: egen Pspouse = max(Spouse) 
keep if Pspouse == 1  

bys year hhid: gen Head_working_ = working if Head == 1 
bys year hhid: gen Head_searching_ = searching if Head == 1 
bys year hhid: gen Spouse_working_ = working if Spouse == 1
bys year hhid: gen Spouse_searching_ = searching if Spouse == 1 

bys year hhid: gen Head_employer_ = employer if Head == 1 
bys year hhid: gen Head_selfemployed_ = selfemployed if Head == 1 
bys year hhid: gen Head_familyworker_ = familyworker if Head == 1 
bys year hhid: gen Head_worker_ = worker if Head == 1 
bys year hhid: gen Head_worker_temp_ = worker_temp if Head == 1
bys year hhid: gen Head_worker_family_ = worker_daily if Head == 1 
bys year hhid: gen Head_education_ = education if Head == 1
bys year hhid: gen Head_age_ = age if Head == 1

bys year hhid: gen Spouse_employer_ = employer if Spouse == 1 
bys year hhid: gen Spouse_selfemployed_ = selfemployed if Spouse == 1 
bys year hhid: gen Spouse_familyworker_ = familyworker if Spouse == 1 
bys year hhid: gen Spouse_worker_ = worker if Spouse == 1 
bys year hhid: gen Spouse_worker_temp_ = worker_temp if Spouse == 1 
bys year hhid: gen Spouse_worker_family_ = worker_daily if Spouse == 1 
bys year hhid: gen Spouse_education_ = education if Spouse == 1
bys year hhid: gen Spouse_age_ = age if Spouse == 1

bys year hhid: gen xx = sex if Head == 1 
bys year hhid: egen Head_sex = max(xx)
drop xx

bys year hhid: egen Head_working = max(Head_working_) 
bys year hhid: egen Head_searching = max(Head_searching_)
bys year hhid: egen Spouse_working = max(Spouse_working_)
bys year hhid: egen Spouse_searching = max(Spouse_searching_)

bys year hhid: egen Head_employer = max(Head_employer_)
bys year hhid: egen Head_selfemployed = max(Head_selfemployed_)
bys year hhid: egen Head_familyworker = max(Head_familyworker_) 
bys year hhid: egen Head_worker = max(Head_worker_)
bys year hhid: egen Head_worker_temp = max(Head_worker_temp_)
bys year hhid: egen Head_worker_family = max(Head_worker_family_)
bys year hhid: egen Head_education = max(Head_education_)
bys year hhid: egen Head_age = max(Head_age_)

bys year hhid: egen Spouse_employer = max(Spouse_employer_)
bys year hhid: egen Spouse_selfemployed = max(Spouse_selfemployed_)
bys year hhid: egen Spouse_familyworker = max(Spouse_familyworker_)
bys year hhid: egen Spouse_worker = max(Spouse_worker_)
bys year hhid: egen Spouse_worker_temp = max(Spouse_worker_temp_)
bys year hhid: egen Spouse_worker_family = max(Spouse_worker_family_)
bys year hhid: egen Spouse_education = max(Spouse_education_)
bys year hhid: egen Spouse_age = max(Spouse_age_)

gen Wife_working = 0 
gen Wife_searching = 0 
gen Wife_employer = 0 
gen Wife_selfemployed = 0 
gen Wife_familyworker =0 
gen Wife_worker = 0 
gen Wife_worker_temp = 0 
gen Wife_worker_family = 0 
gen Wife_age = 0 
gen Wife_education = 0 

gen Husband_working = 0 
gen Husband_searching = 0 
gen Husband_employer = 0 
gen Husband_selfemployed = 0 
gen Husband_familyworker =0 
gen Husband_worker = 0 
gen Husband_worker_temp = 0 
gen Husband_worker_family = 0 
gen Husband_age = 0 
gen Husband_education = 0 

replace Wife_working = Head_working if Head_sex == 2
replace Wife_searching = Head_searching if Head_sex == 2
replace Wife_employer = Head_employer if Head_sex == 2
replace Wife_selfemployed = Head_selfemployed if Head_sex == 2
replace Wife_familyworker = Head_familyworker if Head_sex == 2
replace Wife_worker = Head_worker if Head_sex == 2
replace Wife_worker_temp = Head_worker_temp if Head_sex == 2
replace Wife_worker_family = Head_worker_family if Head_sex == 2
replace Wife_age = Head_age if Head_sex == 2
replace Wife_education = Head_education if Head_sex == 2
replace Wife_working = Spouse_working if Head_sex == 1
replace Wife_searching = Spouse_searching if Head_sex == 1
replace Wife_employer = Spouse_employer if Head_sex == 1
replace Wife_selfemployed = Spouse_selfemployed if Head_sex == 1
replace Wife_familyworker = Spouse_familyworker if Head_sex == 1
replace Wife_worker = Spouse_worker if Head_sex == 1
replace Wife_worker_temp = Spouse_worker_temp if Head_sex == 1
replace Wife_worker_family = Spouse_worker_family if Head_sex == 1
replace Wife_age = Spouse_age if Head_sex == 1
replace Wife_education = Spouse_education if Head_sex == 1

replace Husband_working = Head_working if Head_sex == 1
replace Husband_searching = Head_searching if Head_sex == 1
replace Husband_employer = Head_employer if Head_sex == 1
replace Husband_selfemployed = Head_selfemployed if Head_sex == 1
replace Husband_familyworker = Head_familyworker if Head_sex == 1
replace Husband_worker = Head_worker if Head_sex == 1
replace Husband_worker_temp = Head_worker_temp if Head_sex == 1
replace Husband_worker_family = Head_worker_family if Head_sex == 1
replace Husband_age = Head_age if Head_sex == 1
replace Husband_education = Head_education if Head_sex == 1
replace Husband_working = Spouse_working if Head_sex == 2
replace Husband_searching = Spouse_searching if Head_sex == 2
replace Husband_employer = Spouse_employer if Head_sex == 2
replace Husband_selfemployed = Spouse_selfemployed if Head_sex == 2
replace Husband_familyworker = Spouse_familyworker if Head_sex == 2
replace Husband_worker = Spouse_worker if Head_sex == 2
replace Husband_worker_temp = Spouse_worker_temp if Head_sex == 2
replace Husband_worker_family = Spouse_worker_family if Head_sex == 2
replace Husband_age = Spouse_age if Head_sex == 2
replace Husband_education = Spouse_education if Head_sex == 2


gen Wife_OLF = 1 - Wife_working - Wife_searching
gen Husband_OLF = 1 - Husband_working - Husband_searching

keep if Head == 1

forvalues i = 1993/2005{
	gen I`i' = (year == `i')

	gen x1x`i' = Husband_employer*I`i'
	gen x2x`i' = Husband_selfemployed*I`i'
	gen x3x`i' = Husband_OLF*I`i'
	gen x4x`i' = Husband_searching*I`i'
	gen x5x`i' = x3x`i'+x4x`i'
	gen x6x`i' = Husband_working*I`i'
}

rename I1996 i1996

gen manufacturing = 0 
replace manufacturing = 1 if manu == 1

gen wife_manu_ent = 0 
replace wife_manu_ent = 1 if Wife_employer == 1 & manufacturing == 1
gen husband_manu_ent = 0 
replace husband_manu_ent = 1 if Husband_employer == 1 & manufacturing == 1

**graph
reg wife_manu_ent I* x4x*  Wife_age Wife_edu Husband_age Husband_edu if Husband_working ==  1 | Husband_searching == 1 | Husband_employer == 1 | Husband_selfemployed == 1 | Husband_OLF == 1
coefplot, vertical keep(x4x*) yline(0, lcolor("153 0 51") lpattern(solid)) level(95) xlabel(1 "93" 2 "94" 3 "95" 4 "96" 5 "97" 6 "98" 7 "99" 8 "00" 9 "01" 10 "02" 11 "03" 12 "04" 13 "05"  ) xtitle("Husband Unemployed*Year") ytitle("Prob. of wife being employer in manufacturing sector") yscale(r(-0.02 0.02)) ylabel(-0.02 "-0.02" -0.01 "-0.01" 0 "0" 0.01 "0.01" 0.02 "0.02") mcolor(navy) ciopts(lcolor(navy))

